home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1996 March
/
MacWorld 03:96.toast
/
Online
/
I-Spy scripts
/
Sort file.pl
< prev
Wrap
Perl Script
|
1995-12-23
|
868b
|
34 lines
#!/usr/bin/perl
# Sort file.pl
# This script sorts lines of a file
#
# 12/22/95 Version 1.0
# This script is free, public domain, no strings attached.
# Igor Livshits <igorl@uiuc.edu>
#
# Caveat: MacPerl will require much memory to sort large files: 3MB for InfoMac
$openToWrite= "> ";
$macPathDelimiter= ":";
# Read in the arguments passed to us from the AppleScript agent
#
$workingDirectory= $ARGV[$argumentCounter++] . $macPathDelimiter;
$aFile= $ARGV[$argumentCounter++];
# Read the file into an array
#
open(aFile, $workingDirectory . $aFile) || die "Cannot open $aFile: $!";
@anArray= <aFile>; # read our file, line by line, into array elements
close(aFile);
# Dump the sorted array into our file
#
open(aFile, $openToWrite . $workingDirectory . $aFile) || die "Cannot open $aFile: $!";
print (aFile (sort (@anArray)));
close(aFile);